unit U_fm_rel_saida;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons, Vcl.Mask,
  {RpRave, RpBase, RpSystem, RpDefine, RpCon, RpConDS,} Data.FMTBcd, Data.DB,
  Vcl.Grids, Vcl.DBGrids, Data.SqlExpr, Vcl.ComCtrls, Vcl.ExtCtrls;

type
  Tfm_rel_saida = class(TForm)
    GroupBox1: TGroupBox;
    Label2: TLabel;
    Label1: TLabel;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    EditNfe: TEdit;
    EditCliente: TEdit;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    SpeedButton1: TSpeedButton;
    Date_ini: TDateTimePicker;
    Date_fim: TDateTimePicker;
    GroupBox4: TGroupBox;
    Edit_vend: TEdit;
    Splitter1: TSplitter;
    SpeedButton2: TSpeedButton;
    procedure SpeedButton1Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fm_rel_saida: Tfm_rel_saida;

implementation

{$R *.dfm}

uses U_fm_pesq_cliente, U_dm_principal, U_fm_pesq_vendedor;

procedure Tfm_rel_saida.BitBtn1Click(Sender: TObject);
var
  MySql: String;
  MyWhere: String;
  MyCount: Integer;
const
  MyFieldNF    = 'n_nfe';
  MyFieldCli  = 'cliente';
  MyFieldDtI = 'data_mov';
begin

  MySql :=  'select cliente,'
            +' vendedor,'
            +' tipo_mov, '
            +' data_mov,'
            +' hora_mov, '
            +' tipo_pag,'
            +' n_nfe,'
            +' forma_pag'
            +' from saida ' ;

  MyWhere := EmptyStr;
  MyCount := 0;

  //-
  try
    dm_principal.sq_saida.Close;
    dm_principal.cds_saida.Close;

    if EditNfe.Text <> EmptyStr then
     begin
       MyWhere := 'WHERE ' + MyFieldNF + '=' + QuotedStr(EditNfe.Text);
       MyCount := 1;
     end;
      if Date_ini.Checked then
      MyWhere:=(' AND ' + MyFieldDtI + ' BETWEEN ' + QuotedStr((FormatDateTime('YYYY/MM/DD',Date_ini.Date)))+' AND '+QuotedStr((FormatDateTime('YYYY/MM/DD',Date_fim.Date))));


    //-
    if (EditCliente.Text <> EmptyStr) and (MyCount = 0) then
      begin
         MyWhere := 'WHERE ' + MyFieldCli + '=' + QuotedStr(EditCliente.Text);
         MyCount := 1;

      end


    else



     finally
    dm_principal.sq_saida.SQL.Text := MySql + MyWhere;
    dm_principal.sq_saida.Open;
    dm_principal.cds_saida.Open;

    //RvProject_venda.Open;
    //RvProject_venda.SelectReport('project_saida',false);
    //RvProject_venda.Execute;
    //RvProject_venda.Close;
   end;
end;

procedure Tfm_rel_saida.FormShow(Sender: TObject);
begin
Date_ini.Date:=Date;
Date_fim.Date:=Date;

end;

procedure Tfm_rel_saida.SpeedButton1Click(Sender: TObject);
begin
 fm_pesq_cliente:=Tfm_pesq_cliente.Create(Application);
  fm_pesq_cliente.ShowModal;
 if fm_pesq_cliente.ModalResult=mrok then
 begin
   EditCliente.Text:=dm_principal.cds_clienteNOME.Text;
 end;
end;

procedure Tfm_rel_saida.SpeedButton2Click(Sender: TObject);
begin
fm_pesq_vendedor:=Tfm_pesq_vendedor.Create(Application);
fm_pesq_vendedor.ShowModal;
 if fm_pesq_vendedor.ModalResult=mrok then
 begin
   Edit_vend.Text:=dm_principal.cds_vendedorNOME.Text;
 end;
end;

end.
